<?php 
 
class CategoryModel extends Model{
	public $table="blog_category";
	//获得所有栏目
	public function getall(){
		return $this->order('cid ASC')->select();
	}
	//添加栏目
	public function addCategory($data){
		if (empty($data['catname'])) {
			$this->error='栏目名不能为空';
			return false;
		}
		return $this->insert($data);	
	}
	public function editCategory($data){
		if(!$this->isEmpty($data)) return false;
		if($this->where("cid<>{$data['cid']} && catname='{$data['catname']}'")->select()){
			$this->error='栏目名已经存在';
			return false;
		}
		return $this->where(" cid = {$data['cid']} ")->update($data);

	}
	private function isEmpty($data){
		if(empty($data['catname'])){
			$this->error='栏目名不能为空';
			return false;
		}
		 return true;

	}

	public function deleteCategory($data){
		return $this->delete($data);
	}
}


 ?>